<template>
  <div class="prescription-container">
    <div class="prescription-examine-container">
      <div class="prescription-title">
        <div class="title-left"><span>检查治疗项</span></div>
        <div class="btn-right">
          <el-button @click="addCheckItem">检查检验</el-button>
        </div>
      </div>
      <div
        class="prescription-content"
        v-if="checkItemsForm.check_items.length"
      >
        <el-form
          :model="checkItemsForm"
          ref="checkItemsForm"
          label-width="100px"
          class="check-item-dynamic"
        >
          <!-- 已支付列表 -->
          <div
            class="payed-container"
            :class="
              checkItemsForm.check_items.filter(
                (p) => p.check_item_status !== 2
              ).length
                ? 'payed-split-line'
                : ''
            "
            v-if="
              checkItemsForm.check_items.filter((p) => p.check_item_status == 2)
                .length
            "
          >
            <el-form-item
              class="form-item"
              v-for="(domain, index) in checkItemsForm.check_items.filter(
                (p) => p.check_item_status == 2
              )"
              :key="domain.key || index"
              :prop="domain.check_item_name"
            >
              <div
                class="pay-icon"
                v-if="domain.check_item_status == 2 && index == 0"
              >
                <img
                  src="../../../assets/img/payOrDrug/image_pay.png"
                  alt=""
                  srcset=""
                />
              </div>
              <el-autocomplete
                class="inline-input"
                v-model="domain.check_item_name"
                :disabled="true"
                :fetch-suggestions="checkItemQuerySearch"
                placeholder="请输入检查内容"
                :trigger-on-focus="false"
                @select="
                  (item) => {
                    checkItemHandleSelect(item, index);
                  }
                "
              >
                <template slot="suffix" v-if="domain.own ? false : true">
                  <el-tooltip
                    v-if="domain.check_item_name !== ''"
                    content="该检查治疗项未进行配置，建议你联系诊所管理员在“系统”中进行配置，方便使用"
                    placement="bottom"
                    effect="light"
                  >
                    <i class="el-icon-warning"> </i>
                  </el-tooltip>
                </template>
                <template slot-scope="{ item }">
                  <div class="product-item">
                    <div class="name">
                      <span>{{ item.cost_dict_name }}</span>
                    </div>
                  </div>
                </template>
              </el-autocomplete>
              <el-input
                class="num-input"
                style="width: 75px; margin: 0px 10px"
                placeholder="次数"
                v-model.number="domain.check_item_number"
                :disabled="true"
                @keyup.native="
                  (val) => {
                    checkItemNumberChange(val, index);
                  }
                "
              ></el-input>
              <div class="price">
                <span>￥{{ domain.amount | moneyFormat }}</span>
              </div>
              <div class="btn">
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printCheckItem(domain,1)"
                  ></el-button>
                </el-tooltip>
              </div>
            </el-form-item>
          </div>
          <!-- 未支付检查项列表 -->
          <div
            class="nopay-container"
            v-if="
              checkItemsForm.check_items.filter(
                (p) => p.check_item_status !== 2
              ).length
            "
          >
            <el-form-item
              class="form-item"
              v-for="(domain, index) in checkItemsForm.check_items.filter(
                (p) => p.check_item_status !== 2
              )"
              :key="domain.key || index"
              :prop="domain.check_item_name"
            >
              <el-autocomplete
                class="inline-input"
                v-model="domain.check_item_name"
                :fetch-suggestions="checkItemQuerySearch"
                placeholder="请输入检查内容"
                :trigger-on-focus="false"
                @change="
                  (val) => {
                    checkItemChange(val, 'checkitem', index);
                  }
                "
                @select="
                  (item) => {
                    checkItemHandleSelect(item, index);
                  }
                "
              >
                <template slot="suffix" v-if="domain.own ? false : true">
                  <el-tooltip
                    v-if="domain.check_item_name !== ''"
                    content="该检查治疗项未进行配置，建议你联系诊所管理员在“系统”中进行配置，方便使用"
                    placement="bottom"
                    effect="light"
                  >
                    <i class="el-icon-warning"> </i>
                  </el-tooltip>
                </template>
                <template slot-scope="{ item }">
                  <div class="product-item">
                    <div class="name">
                      <span>{{ item.cost_dict_name }}</span>
                    </div>
                  </div>
                </template>
              </el-autocomplete>
              <el-input
                class="num-input"
                style="width: 75px; margin: 0px 10px"
                placeholder="次数"
                v-model.number="domain.check_item_number"
                ref="checkItemNumber"
                @keyup.native="
                  (val) => {
                    checkItemNumberChange(val, index);
                  }
                "
              ></el-input>
              <div class="price">
                <span>￥{{ domain.amount | moneyFormat }}</span>
              </div>
              <div class="btn">
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printCheckItem(domain, 1)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="删除" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-delete"
                    @click.prevent="removeCheckItem(domain)"
                  ></el-button>
                </el-tooltip>
              </div>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </div>
    <div class="prescription-prescription-container">
      <div class="prescription-title">
        <div class="title-left"><span>处方医嘱</span></div>
        <div class="btn-right">
          <el-button
            @click="addPatentMedicine"
            v-if="prescriptionBtnShowList.filter((p) => p == '成药处方').length"
            >成药处方</el-button
          >
          <el-button
            @click="addYinpian"
            v-if="prescriptionBtnShowList.filter((p) => p == '饮片处方').length"
            >饮片处方</el-button
          >
          <el-button
            @click="addTransfuse"
            v-if="prescriptionBtnShowList.filter((p) => p == '注射液').length"
            >输液处方</el-button
          >
          <el-button
            @click="addCommonlyPrescription"
            v-if="prescriptionBtnShowList.filter((p) => p == '常用处方').length"
            >常用处方</el-button
          >
        </div>
      </div>
      <!-- 成药处方 -->
      <div
        class="prescription-content"
        v-if="payedChengyaoList.length || chengyaoList.length"
      >
        <!-- 已收费成药处方 -->
        <template v-for="(patentMedicine, index) in payedChengyaoList">
          <div
            class="prescription-payed-container"
            v-if="payedChengyaoList.length"
          >
            <div class="pay-icon">
              <img
                src="../../../assets/img/payOrDrug/image_pay.png"
                alt=""
                srcset=""
              />
            </div>
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>成药处方{{ index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(patentMedicine)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(patentMedicine)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <el-form
              :model="patentMedicine"
              disabled
              ref="patentMedicineValidateForm"
              label-width="100px"
              class="injection-dynamic"
            >
              <el-form-item class="form-item-title">
                <div class="form-item-left">
                  <div class="product-name-input">药品名称</div>
                  <div class="use-info-input">用法</div>
                  <div class="frequency-input">用药频率</div>
                  <div class="single-container">单次剂量</div>
                  <div class="total-num-input">开药量</div>
                  <div class="price" style="text-align: center">
                    <span>金额</span>
                  </div>
                </div>
                <div class="btn"></div>
              </el-form-item>
              <el-form-item
                class="form-item-detail"
                v-for="(domain, idx) in patentMedicine.details"
                :key="domain.key"
                :prop="'details.' + idx + '.value'"
              >
                <div class="item-detail-main">
                  <div class="form-item-left">
                    <el-autocomplete
                      class="product-name-input"
                      v-model="domain.product_name"
                      :fetch-suggestions="cyQuerySearch"
                      placeholder="请输入药品名称"
                      :trigger-on-focus="false"
                      @focus="addPatentItem(index, idx)"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'product');
                        }
                      "
                      @select="
                        (item) => {
                          cyProHandleSelect(item, index, idx);
                        }
                      "
                    >
                      <template slot="suffix" v-if="domain.own ? false : true">
                        <el-tooltip
                          v-if="domain.product_name !== ''"
                          content="该药品不在您的药库中，建议您更换其他药品"
                          placement="bottom"
                          effect="light"
                        >
                          <i class="el-icon-warning"> </i>
                        </el-tooltip>
                      </template>
                      <template slot-scope="{ item }">
                        <div
                          class="product-item-container"
                          style="
                            display: flex;
                            justify-content: flex-start;
                            align-items: flex-start;
                          "
                        >
                          <div class="icon-container" style="margin-right: 5px">
                            <i
                              class="el-icon-success"
                              style="color: green"
                              v-if="item.Own"
                            ></i>
                            <i class="el-icon-warning" v-else></i>
                          </div>
                          <div class="product-item" style="padding: 5px 0px">
                            <div
                              class="name"
                              style="font-weight: bold; line-height: 22px"
                            >
                              <span class="name-name">{{
                                item.product_name
                              }}</span
                              ><span class="name-pack">({{ item.pack }})</span>
                            </div>
                            <div
                              class="producer"
                              style="color: #999; line-height: 22px"
                            >
                              <span>{{ item.production }}</span>
                            </div>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <el-autocomplete
                      class="use-info-input"
                      v-model="domain.use_way"
                      :fetch-suggestions="cyyfQuerySearch"
                      placeholder="用法"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'yf');
                        }
                      "
                      @select="
                        (val) => {
                          usageHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template> </el-autocomplete
                    ><el-autocomplete
                      class="frequency-input"
                      v-model="domain.medication_rate"
                      :fetch-suggestions="medicationRateQuerySearch"
                      placeholder="用药频次"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'yypl');
                        }
                      "
                      @select="
                        (val) => {
                          medicationRateHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <div class="single-container">
                      <el-input
                        class="single-num-input"
                        v-model="domain.single_dose"
                        oninput ="this.value=this.value.match(/\d+\.?\d{0,2}/)"
                        placeholder="剂量"
                      ></el-input>
                      <el-autocomplete
                        class="single-unit-input"
                        v-model="domain.single_unit"
                        :fetch-suggestions="singleUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'single_unit');
                          }
                        "
                        @select="
                          (val) => {
                            singleUnitHandleSelect(val, index, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </div>
                    <div class="total-num-input">
                      <el-input
                        class="num-input"
                        v-model.number="domain.number"
                        placeholder="数量"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'number');
                          }
                        "
                        @keyup.native="
                          (val) => {
                            cyNumberChange(val, index, idx);
                          }
                        "
                      ></el-input>
                      <el-autocomplete
                        class="number-unit-input"
                        v-model="domain.unit"
                        :fetch-suggestions="numberUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'unit');
                          }
                        "
                        @select="
                          (val) => {
                            numberUnitHandleSelect(val, index, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </div>

                    <div class="price" style="text-align: center">
                      <span>￥{{ domain.amount | moneyFormat }}</span>
                    </div>
                  </div>
                  <div class="btn">
                    <!-- <el-button
                      class="icon-btn"
                      icon="el-icon-delete"
                      @click.prevent="removePatentItem(domain, index, idx)"
                    ></el-button> -->
                  </div>
                </div>

                <div class="item-details-info" v-if="domain.own">
                  <span v-if="domain.number > domain.stock" class="info-tip"
                    >当前药品{{
                      domain.stock <= 0
                        ? "库存不足"
                        : `仅剩余${domain.stock}${domain.unit}`
                    }}，建议您更换其他药品</span
                  >
                </div>
              </el-form-item>
            </el-form>
          </div>
        </template>
        <!-- 未收费成药处方 -->
        <template v-for="(patentMedicine, index) in chengyaoList">
          <div class="prescription-nopay-container" v-if="chengyaoList.length">
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>成药处方{{ payedChengyaoList.length + index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(patentMedicine)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(patentMedicine)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="删除" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-delete"
                    @click="removePatentMedicineItem(index)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <el-form
              :model="patentMedicine"
              ref="patentMedicineValidateForm"
              label-width="100px"
              class="injection-dynamic"
            >
              <el-form-item class="form-item-title">
                <div class="form-item-left">
                  <div class="product-name-input">药品名称</div>
                  <div class="use-info-input">用法</div>
                  <div class="frequency-input">用药频率</div>
                  <div class="single-container">单次剂量</div>
                  <div class="total-num-input">开药量</div>
                  <div class="price" style="text-align: center">
                    <span>金额</span>
                  </div>
                </div>
                <div class="btn"></div>
              </el-form-item>
              <el-form-item
                class="form-item-detail"
                v-for="(domain, idx) in patentMedicine.details"
                :key="domain.key"
                :prop="'details.' + idx + '.value'"
              >
                <div class="item-detail-main">
                  <div class="form-item-left">
                    <el-autocomplete
                      class="product-name-input"
                      v-model="domain.product_name"
                      :fetch-suggestions="cyQuerySearch"
                      placeholder="请输入药品名称"
                      :trigger-on-focus="false"
                      @focus="addPatentItem(index, idx)"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'product');
                        }
                      "
                      @select="
                        (item) => {
                          cyProHandleSelect(item, index, idx);
                        }
                      "
                    >
                      <template slot="suffix" v-if="domain.own ? false : true">
                        <el-tooltip
                          v-if="domain.product_name !== ''"
                          content="该药品不在您的药库中，建议您更换其他药品"
                          placement="bottom"
                          effect="light"
                        >
                          <i class="el-icon-warning"> </i>
                        </el-tooltip>
                      </template>
                      <template slot-scope="{ item }">
                        <div
                          class="product-item-container"
                          style="
                            display: flex;
                            justify-content: flex-start;
                            align-items: flex-start;
                          "
                        >
                          <div class="icon-container" style="margin-right: 5px">
                            <i
                              class="el-icon-success"
                              style="color: green"
                              v-if="item.Own"
                            ></i>
                            <i class="el-icon-warning" v-else></i>
                          </div>
                          <div class="product-item" style="padding: 5px 0px">
                            <div
                              class="name"
                              style="font-weight: bold; line-height: 22px"
                            >
                              <span class="name-name">{{
                                item.product_name
                              }}</span
                              ><span class="name-pack">({{ item.pack }})</span>
                            </div>
                            <div
                              class="producer"
                              style="color: #999; line-height: 22px"
                            >
                              <span>{{ item.production }}</span>
                            </div>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <el-autocomplete
                      class="use-info-input"
                      v-model="domain.use_way"
                      :fetch-suggestions="cyyfQuerySearch"
                      placeholder="用法"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'yf');
                        }
                      "
                      @select="
                        (val) => {
                          usageHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template> </el-autocomplete
                    ><el-autocomplete
                      class="frequency-input"
                      v-model="domain.medication_rate"
                      :fetch-suggestions="medicationRateQuerySearch"
                      placeholder="用药频次"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          cyChange(val, index, idx, 'yypl');
                        }
                      "
                      @select="
                        (val) => {
                          medicationRateHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <div class="single-container">
                      <el-input
                        class="single-num-input"
                        v-model="domain.single_dose"
                        oninput ="this.value=this.value.match(/\d+\.?\d{0,2}/)"
                        placeholder="剂量"
                      ></el-input>
                      <el-autocomplete
                        class="single-unit-input"
                        v-model="domain.single_unit"
                        :fetch-suggestions="singleUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'single_unit');
                          }
                        "
                        @select="
                          (val) => {
                            singleUnitHandleSelect(val, index, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </div>
                    <div class="total-num-input">
                      <el-input
                        class="num-input"
                        v-model.number="domain.number"
                        oninput ="value=value.replace(/[^0-9.]/g,'')"
                        placeholder="数量"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'number');
                          }
                        "
                        @keyup.native="
                          (val) => {
                            cyNumberChange(val, index, idx);
                          }
                        "
                      ></el-input>
                      <el-autocomplete
                        class="number-unit-input"
                        v-model="domain.unit"
                        :fetch-suggestions="numberUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            cyChange(val, index, idx, 'unit');
                          }
                        "
                        @select="
                          (val) => {
                            numberUnitHandleSelect(val, index, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </div>

                    <div class="price" style="text-align: center">
                      <span>￥{{ domain.amount | moneyFormat }}</span>
                    </div>
                  </div>
                  <div class="btn">
                    <el-button
                      class="icon-btn"
                      icon="el-icon-delete"
                      @click.prevent="removePatentItem(domain, index, idx)"
                    ></el-button>
                  </div>
                </div>

                <div class="item-details-info" v-if="domain.own">
                  <span
                    v-if="
                      domain.number > domain.stock && domain.product_name !== ''
                    "
                    class="info-tip"
                    >当前药品{{
                      domain.stock <= 0
                        ? "库存不足"
                        : `仅剩余${domain.stock}${domain.unit}`
                    }}，建议您更换其他药品</span
                  >
                </div>
              </el-form-item>
            </el-form>
          </div>
        </template>
      </div>
      <!-- 饮片处方 -->
      <div
        class="prescription-content"
        v-if="payedYinpianList.length || yinpianList.length"
      >
        <template v-for="(yinpian, index) in payedYinpianList">
          <div class="prescription-payed-container">
            <div class="pay-icon">
              <img
                src="../../../assets/img/payOrDrug/image_pay.png"
                alt=""
                srcset=""
              />
            </div>
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>饮片处方{{ index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(yinpian)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(yinpian)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <div class="prescription-info-container">
              <table
                class="info-table"
                border="1"
                width="100%"
                cellspacing="0"
                cellpadding="10"
                style="width: 100%; border-collapse: collapse"
              >
                <tbody>
                  <tr class="table-td">
                    <td class="table-td" align="center">剂数</td>
                    <td class="table-td">
                      <div class="jishu">
                        <el-input
                          v-model="yinpian.remark.js"
                          disabled
                          placeholder="剂数"
                        ></el-input>
                      </div>
                    </td>
                    <td class="table-td" align="center">每日剂量</td>
                    <td class="table-td mrjl">
                      <div class="jishu">
                        <el-input
                          v-model="yinpian.remark.mrjl"
                          disabled
                          placeholder="每日剂量"
                        ></el-input>
                        <p class="unit">剂</p>
                      </div>
                    </td>
                    <td class="table-td" align="center">用药频率</td>
                    <td class="table-td">
                      <el-autocomplete
                        class="use-info-input"
                        v-model="yinpian.remark.yypl"
                        disabled
                        :fetch-suggestions="yyplQuerySearch"
                        placeholder="用药频率"
                        :trigger-on-focus="true"
                        @select="
                          (val) => {
                            yyplHandleSelect(val, index);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </td>
                  </tr>
                  <tr class="table-td">
                    <td class="table-td" align="center">用法</td>
                    <td class="table-td" colspan="5">
                      <div>
                        <el-autocomplete
                          class="use-info-input"
                          v-model="yinpian.remark.yf"
                          disabled
                          :fetch-suggestions="yfQuerySearch"
                          placeholder="用法"
                          :trigger-on-focus="true"
                          @select="
                            (val) => {
                              yfHandleSelect(val, index);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </div>
                    </td>
                  </tr>
                  <tr class="table-td">
                    <td class="table-td" align="center">服用要求</td>
                    <td class="table-td" colspan="5">
                      <div>
                        <el-autocomplete
                          class="use-info-input"
                          v-model="yinpian.remark.fyyq"
                          disabled
                          :fetch-suggestions="fyyqQuerySearch"
                          placeholder="服用要求"
                          :trigger-on-focus="true"
                          @select="
                            (val) => {
                              fyyqHandleSelect(val, index);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <el-form
              :model="yinpian"
              disabled
              ref="yinpianValidateForm"
              label-width="100px"
              class="injection-dynamic"
            >
              <el-form-item
                class="form-item-detail"
                v-for="(domain, idx) in yinpian.details"
                :key="domain.key"
                :prop="'details.' + idx + '.value'"
              >
                <div class="item-detail-main">
                  <div class="form-item-left">
                    <el-autocomplete
                      class="product-name-input"
                      v-model="domain.product_name"
                      :fetch-suggestions="ypQuerySearch"
                      placeholder="请输入饮片名称"
                      :trigger-on-focus="false"
                      @focus="addYinpinItem(index, idx)"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'product');
                        }
                      "
                      @select="
                        (val) => {
                          ypProHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot="suffix" v-if="domain.own ? false : true">
                        <el-tooltip
                          v-if="domain.product_name !== ''"
                          content="该药品不在您的药库中，建议您更换其他药品"
                          placement="bottom"
                          effect="light"
                        >
                          <i class="el-icon-warning"> </i>
                        </el-tooltip>
                      </template>
                      <template slot-scope="{ item }">
                        <div
                          class="product-item-container"
                          style="
                            display: flex;
                            justify-content: flex-start;
                            align-items: flex-start;
                          "
                        >
                          <div class="icon-container" style="margin-right: 5px">
                            <i
                              class="el-icon-success"
                              style="color: green"
                              v-if="item.Own"
                            ></i>
                            <i class="el-icon-warning" v-else></i>
                          </div>
                          <div class="product-item" style="padding: 5px 0px">
                            <div
                              class="name"
                              style="font-weight: bold; line-height: 22px"
                            >
                              <span class="name-name">{{
                                item.product_name
                              }}</span
                              ><span class="name-pack">({{ item.pack }})</span>
                            </div>
                            <div
                              class="producer"
                              style="color: #999; line-height: 22px"
                            >
                              <span>{{ item.production }}</span>
                            </div>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <el-input
                      class="num-input append-input"
                      v-model="domain.number"
                      oninput ="value=value.replace(/[^0-9.]/g,'')"
                      placeholder="数量"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'number');
                        }
                      "
                      @keyup.native="
                        (val) => {
                          ypNumberChange(val, index, idx);
                        }
                      "
                    >
                      <template slot="append">g</template>
                    </el-input>
                    <el-autocomplete
                      class="remark-input"
                      v-model="domain.remark"
                      :fetch-suggestions="remarkQuerySearch"
                      placeholder="备注"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'remark');
                        }
                      "
                      @select="
                        (val) => {
                          remarkHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <div class="price" style="text-align: center">
                      <span>￥{{ domain.amount | moneyFormat }}</span>
                    </div>
                  </div>
                  <div class="btn"></div>
                </div>
                <div class="item-details-info" v-if="domain.own">
                  <span
                    v-if="
                      domain.number > domain.stock && domain.product_name !== ''
                    "
                    class="info-tip"
                    >当前药品{{
                      domain.stock <= 0
                        ? "库存不足"
                        : `仅剩余${domain.stock}${domain.unit}`
                    }}，建议您更换其他药品</span
                  >
                </div>
              </el-form-item>
            </el-form>
          </div>
        </template>
        <template v-for="(yinpian, index) in yinpianList">
          <div class="prescription-nopay-container" v-if="yinpianList.length">
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>饮片处方{{ payedYinpianList.length + index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(yinpian)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(yinpian)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="删除" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-delete"
                    @click="removeYinpian(index)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <div class="prescription-info-container">
              <table
                class="info-table"
                border="1"
                width="100%"
                cellspacing="0"
                cellpadding="10"
                style="width: 100%; border-collapse: collapse"
              >
                <tbody>
                  <tr class="table-td">
                    <td class="table-td" align="center">剂数</td>
                    <td class="table-td">
                      <div class="jishu">
                        <el-input
                          v-model="yinpian.remark.js"
                          @change="
                            (val) => {
                              ypRemarkChange(val, index);
                            }
                          "
                          placeholder="剂数"
                        ></el-input>
                      </div>
                    </td>
                    <td class="table-td" align="center">每日剂量</td>
                    <td class="table-td mrjl">
                      <div class="jishu">
                        <el-input
                          v-model="yinpian.remark.mrjl"
                          @change="
                            (val) => {
                              ypRemarkChange(val, index);
                            }
                          "
                          placeholder="每日剂量"
                        ></el-input>
                        <p class="unit">剂</p>
                      </div>
                    </td>
                    <td class="table-td" align="center">用药频率</td>
                    <td class="table-td">
                      <el-autocomplete
                        class="use-info-input"
                        v-model="yinpian.remark.yypl"
                        :fetch-suggestions="yyplQuerySearch"
                        placeholder="用药频率"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            ypRemarkChange(val, index);
                          }
                        "
                        @select="
                          (val) => {
                            yyplHandleSelect(val, index);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                    </td>
                  </tr>
                  <tr class="table-td">
                    <td class="table-td" align="center">用法</td>
                    <td class="table-td" colspan="5">
                      <div>
                        <el-autocomplete
                          class="use-info-input"
                          v-model="yinpian.remark.yf"
                          :fetch-suggestions="yfQuerySearch"
                          placeholder="用法"
                          :trigger-on-focus="true"
                          @change="
                            (val) => {
                              ypRemarkChange(val, index);
                            }
                          "
                          @select="
                            (val) => {
                              yfHandleSelect(val, index);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </div>
                    </td>
                  </tr>
                  <tr class="table-td">
                    <td class="table-td" align="center">服用要求</td>
                    <td class="table-td" colspan="5">
                      <div>
                        <el-autocomplete
                          class="use-info-input"
                          v-model="yinpian.remark.fyyq"
                          :fetch-suggestions="fyyqQuerySearch"
                          placeholder="服用要求"
                          :trigger-on-focus="true"
                          @change="
                            (val) => {
                              ypRemarkChange(val, index);
                            }
                          "
                          @select="
                            (val) => {
                              fyyqHandleSelect(val, index);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <el-form
              :model="yinpian"
              ref="yinpianValidateForm"
              label-width="100px"
              class="injection-dynamic"
            >
              <el-form-item
                class="form-item-detail"
                v-for="(domain, idx) in yinpian.details"
                :key="domain.key"
                :prop="'details.' + idx + '.value'"
              >
                <div class="item-detail-main">
                  <div class="form-item-left">
                    <el-autocomplete
                      class="product-name-input"
                      v-model="domain.product_name"
                      :fetch-suggestions="ypQuerySearch"
                      placeholder="请输入饮片名称"
                      :trigger-on-focus="false"
                      @focus="addYinpinItem(index, idx)"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'product');
                        }
                      "
                      @select="
                        (val) => {
                          ypProHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot="suffix" v-if="domain.own ? false : true">
                        <el-tooltip
                          v-if="domain.product_name !== ''"
                          content="该药品不在您的药库中，建议您更换其他药品"
                          placement="bottom"
                          effect="light"
                        >
                          <i class="el-icon-warning"> </i>
                        </el-tooltip>
                      </template>
                      <template slot-scope="{ item }">
                        <div
                          class="product-item-container"
                          style="
                            display: flex;
                            justify-content: flex-start;
                            align-items: flex-start;
                          "
                        >
                          <div class="icon-container" style="margin-right: 5px">
                            <i
                              class="el-icon-success"
                              style="color: green"
                              v-if="item.Own"
                            ></i>
                            <i class="el-icon-warning" v-else></i>
                          </div>
                          <div class="product-item" style="padding: 5px 0px">
                            <div
                              class="name"
                              style="font-weight: bold; line-height: 22px"
                            >
                              <span class="name-name">{{
                                item.product_name
                              }}</span
                              ><span class="name-pack">({{ item.pack }})</span>
                            </div>
                            <div
                              class="producer"
                              style="color: #999; line-height: 22px"
                            >
                              <span>{{ item.production }}</span>
                            </div>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <el-input
                      class="num-input append-input"
                      v-model.number="domain.number"
                      oninput ="value=value.replace(/[^0-9.]/g,'')"
                      placeholder="数量"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'number');
                        }
                      "
                      @keyup.native="
                        (val) => {
                          ypNumberChange(val, index, idx);
                        }
                      "
                    >
                      <template slot="append">g</template>
                    </el-input>
                    <el-autocomplete
                      class="remark-input"
                      v-model="domain.remark"
                      :fetch-suggestions="remarkQuerySearch"
                      placeholder="备注"
                      :trigger-on-focus="true"
                      @change="
                        (val) => {
                          ypDetailChange(val, index, idx, 'remark');
                        }
                      "
                      @select="
                        (val) => {
                          remarkHandleSelect(val, index, idx);
                        }
                      "
                    >
                      <template slot-scope="{ item }">
                        <div class="useage-item">
                          <div class="name">
                            <span>{{ item }}</span>
                          </div>
                        </div>
                      </template>
                    </el-autocomplete>
                    <div class="price" style="text-align: center">
                      <span>￥{{ domain.amount | moneyFormat }}</span>
                    </div>
                  </div>
                  <div class="btn">
                    <el-button
                      class="icon-btn"
                      icon="el-icon-delete"
                      @click.prevent="removeYinpianItem(domain, index, idx)"
                    ></el-button>
                  </div>
                </div>
                <div class="item-details-info" v-if="domain.own">
                  <span
                    v-if="
                      domain.number > domain.stock && domain.product_name !== ''
                    "
                    class="info-tip"
                    >当前药品{{
                      domain.stock <= 0
                        ? "库存不足"
                        : `仅剩余${domain.stock}${domain.unit}`
                    }}，建议您更换其他药品</span
                  >
                </div>
              </el-form-item>
            </el-form>
          </div>
        </template>
      </div>
      <!-- 输液处方 -->
      <div
        class="prescription-content"
        v-if="shuyeList.length || payedShuyeList.length"
      >
        <!-- 已收费输液处方 -->
        <template v-for="(shuyeItem, index) in payedShuyeList">
          <div
            class="prescription-payed-container"
            v-if="payedShuyeList.length"
          >
            <div class="pay-icon">
              <img
                src="../../../assets/img/payOrDrug/image_pay.png"
                alt=""
                srcset=""
              />
            </div>
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>输液处方{{ index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(shuyeItem)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(shuyeItem)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <div
              class="shuye-group-item"
              v-for="(shuye, shuyeidx) in shuyeItem.group"
              :key="shuyeidx"
            >
              <div class="shuye-group-top">
                <div class="group-top-left">
                  <p class="group-num">
                    <span>组{{ shuyeidx + 1 }}</span>
                  </p>
                  <!-- 已收费不显示 -->
                  <div class="group-btn" v-if="false">
                    <el-button
                      type="text"
                      @click="addShuyeGroup(index, shuyeidx)"
                      >添加组</el-button
                    >
                    <el-button
                      type="text"
                      @click="removeShuyeGroup(index, shuyeidx)"
                      >删除组</el-button
                    >
                  </div>
                </div>
              </div>
              <div class="prescription-info-container">
                <table
                  class="info-table shuye-info-table"
                  border="1"
                  width="100%"
                  cellspacing="0"
                  cellpadding="10"
                  style="width: 100%; border-collapse: collapse"
                >
                  <tbody>
                    <tr class="table-td">
                      <td class="table-td" align="center">用法</td>
                      <td class="table-td">
                        <div>
                          <el-autocomplete
                            class="use-info-input"
                            v-model="shuye.remark.yf"
                            disabled
                            :fetch-suggestions="syyfQuerySearch"
                            placeholder="用法"
                            :trigger-on-focus="true"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            @select="
                              (val) => {
                                syyfHandleSelect(val, index, shuyeidx);
                              }
                            "
                          >
                            <template slot-scope="{ item }">
                              <div class="useage-item">
                                <div class="name">
                                  <span>{{ item }}</span>
                                </div>
                              </div>
                            </template>
                          </el-autocomplete>
                        </div>
                      </td>
                      <td class="table-td" align="center">滴速</td>
                      <td class="table-td mrjl">
                        <div class="jishu">
                          <el-input
                            v-model="shuye.remark.ds"
                            disabled
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            placeholder="滴速"
                          ></el-input>
                          <el-autocomplete
                            class="use-info-input"
                            v-model="shuye.remark.ds_unit"
                            disabled
                            placeholder="单位"
                            :fetch-suggestions="dsQuerySearch"
                            :trigger-on-focus="true"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            @select="
                              (val) => {
                                dsHandleSelect(val, index, shuyeidx);
                              }
                            "
                          >
                            <template slot-scope="{ item }">
                              <div class="useage-item">
                                <div class="name">
                                  <span>{{ item }}</span>
                                </div>
                              </div>
                            </template>
                          </el-autocomplete>
                        </div>
                      </td>
                      <td class="table-td" align="center">用药频率</td>
                      <td class="table-td">
                        <el-autocomplete
                          class="use-info-input"
                          v-model="shuye.remark.yypl"
                          disabled
                          :fetch-suggestions="syplQuerySearch"
                          placeholder="用药频率"
                          :trigger-on-focus="true"
                          @change="
                            (val) => {
                              syRemarkChange(val, index, shuyeidx);
                            }
                          "
                          @select="
                            (val) => {
                              syplHandleSelect(val, index, shuyeidx);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </td>
                    </tr>
                    <tr class="table-td">
                      <td class="table-td" align="center">起始日期</td>
                      <td class="table-td" colspan="3">
                        <div>
                          <el-date-picker
                            v-model="shuye.remark.qzrq"
                            disabled
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            type="date"
                            placeholder="选择日期"
                          >
                          </el-date-picker>
                        </div>
                      </td>
                      <td class="table-td" align="center">连续天数</td>
                      <td class="table-td">
                        <div class="jishu">
                          <el-input
                            v-model="shuye.remark.lxts"
                            disabled
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            placeholder="天数"
                          ></el-input>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <el-form
                :model="shuye"
                disabled
                ref="yinpianValidateForm"
                label-width="100px"
                class="injection-dynamic"
              >
                <el-form-item
                  class="form-item-detail"
                  v-for="(domain, idx) in shuye.details"
                  :key="domain.key || idx"
                  :prop="'details.' + idx + '.value'"
                >
                  <div class="item-detail-main">
                    <div class="form-item-left">
                      <el-autocomplete
                        class="product-name-input"
                        v-model="domain.product_name"
                        :fetch-suggestions="syProQuerySearch"
                        placeholder="请输入药品名称"
                        :trigger-on-focus="false"
                        @focus="addShuyeItem(index, shuyeidx, idx)"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'product'
                            );
                          }
                        "
                        @select="
                          (item) => {
                            syProHandleSelect(item, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template
                          slot="suffix"
                          v-if="domain.own ? false : true"
                        >
                          <el-tooltip
                            v-if="domain.product_name !== ''"
                            content="该药品不在您的药库中，建议您更换其他药品"
                            placement="bottom"
                            effect="light"
                          >
                            <i class="el-icon-warning"> </i>
                          </el-tooltip>
                        </template>
                        <template slot-scope="{ item }">
                          <div
                            class="product-item-container"
                            style="
                              display: flex;
                              justify-content: flex-start;
                              align-items: flex-start;
                            "
                          >
                            <div
                              class="icon-container"
                              style="margin-right: 5px"
                            >
                              <i
                                class="el-icon-success"
                                style="color: green"
                                v-if="item.Own"
                              ></i>
                              <i class="el-icon-warning" v-else></i>
                            </div>
                            <div class="product-item" style="padding: 5px 0px">
                              <div
                                class="name"
                                style="font-weight: bold; line-height: 22px"
                              >
                                <span class="name-name">{{
                                  item.product_name
                                }}</span
                                ><span class="name-pack"
                                  >({{ item.pack }})</span
                                >
                              </div>
                              <div
                                class="producer"
                                style="color: #999; line-height: 22px"
                              >
                                <span>{{ item.production }}</span>
                              </div>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <el-input
                        class="num-input"
                        v-model="domain.single_dose"
                        oninput ="this.value=this.value.match(/\d+\.?\d{0,2}/)"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'single_dose'
                            );
                          }
                        "
                        placeholder="剂量"
                      ></el-input>
                      <el-autocomplete
                        class="inline-input"
                        v-model="domain.single_unit"
                        :fetch-suggestions="singleUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'single_unit'
                            );
                          }
                        "
                        @select="
                          (val) => {
                            sySingleUnitHandleSelect(val, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <el-input
                        class="num-input"
                        v-model="domain.skin_test"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'skin_test'
                            );
                          }
                        "
                        placeholder="皮试"
                      ></el-input>
                      <el-input
                        class="num-input"
                        v-model.number="domain.number"
                        oninput ="value=value.replace(/[^0-9.]/g,'')"
                        placeholder="开药量"
                        @change="
                          (val) => {
                            syDetailChange(val, index, shuyeidx, idx, 'number');
                          }
                        "
                        @keyup.native="
                          (val) => {
                            syNumberChange(val, index, shuyeidx, idx);
                          }
                        "
                      ></el-input>
                      <el-autocomplete
                        class="inline-input"
                        v-model="domain.unit"
                        :fetch-suggestions="numberUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            syDetailChange(val, index, shuyeidx, idx, 'unit');
                          }
                        "
                        @select="
                          (val) => {
                            syNumberUnitHandleSelect(val, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <div class="price" style="text-align: center">
                        <span>￥{{ domain.amount | moneyFormat }}</span>
                      </div>
                    </div>
                    <div class="btn">
                      <el-button
                        class="icon-btn"
                        icon="el-icon-delete"
                        @click.prevent="
                          removeShuyeItem(domain, index, shuyeidx, idx)
                        "
                      ></el-button>
                    </div>
                  </div>
                  <!-- <div class="item-details-info" v-if="domain.own">
                    <span v-if="(domain.number > domain.stock)&&domain.product_name!==''" class="info-tip"
                      >当前药品{{
                        domain.stock <= 0
                          ? "库存不足"
                          : `仅剩余${domain.stock}${domain.unit}`
                      }}，建议您更换其他药品</span
                    >
                  </div> -->
                </el-form-item>
              </el-form>
              <!-- 已收费，不显示 -->
              <!-- <div class="add-item-line">
                <el-button
                  type="text"
                  @click="addShuyeItem(index, shuyeidx, -1)"
                  >添加药品</el-button
                >
              </div> -->
            </div>
          </div>
        </template>
        <!-- 未收费输液处方 -->
        <template v-for="(shuyeItem, index) in shuyeList">
          <div class="prescription-nopay-container" v-if="shuyeList.length">
            <div class="top-title">
              <div class="title-left">
                <i class="title-icon el-icon-first-aid-kit"></i
                ><span>输液处方{{ index + 1 }}</span>
              </div>
              <div class="btn-right">
                <el-tooltip
                  content="存为常用处方"
                  placement="bottom"
                  effect="light"
                >
                  <el-button
                    class="icon-btn"
                    icon="el-icon-document-add"
                    @click="saveCommonPrescription(shuyeItem)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printItemClick(shuyeItem)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="删除" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-delete"
                    @click="removeShuye(index)"
                  ></el-button>
                </el-tooltip>
              </div>
            </div>
            <div
              class="shuye-group-item"
              v-for="(shuye, shuyeidx) in shuyeItem.group"
              :key="shuyeidx"
            >
              <div class="shuye-group-top">
                <div class="group-top-left">
                  <p class="group-num">
                    <span>组{{ shuyeidx + 1 }}</span>
                  </p>
                  <div class="group-btn">
                    <el-button
                      type="text"
                      @click="addShuyeGroup(index, shuyeidx)"
                      >添加组</el-button
                    >
                    <el-button
                      type="text"
                      :disabled="shuyeItem.group.length==1"
                      @click="removeShuyeGroup(index, shuyeidx)"
                      >删除组</el-button
                    >
                  </div>
                </div>
              </div>
              <div class="prescription-info-container">
                <table
                  class="info-table shuye-info-table"
                  border="1"
                  width="100%"
                  cellspacing="0"
                  cellpadding="10"
                  style="width: 100%; border-collapse: collapse"
                >
                  <tbody>
                    <tr class="table-td">
                      <td class="table-td" align="center">用法</td>
                      <td class="table-td">
                        <div>
                          <el-autocomplete
                            class="use-info-input"
                            v-model="shuye.remark.yf"
                            :fetch-suggestions="syyfQuerySearch"
                            placeholder="用法"
                            :trigger-on-focus="true"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            @select="
                              (val) => {
                                syyfHandleSelect(val, index, shuyeidx);
                              }
                            "
                          >
                            <template slot-scope="{ item }">
                              <div class="useage-item">
                                <div class="name">
                                  <span>{{ item }}</span>
                                </div>
                              </div>
                            </template>
                          </el-autocomplete>
                        </div>
                      </td>
                      <td class="table-td" align="center">滴速</td>
                      <td class="table-td mrjl">
                        <div class="jishu">
                          <el-input
                            v-model="shuye.remark.ds"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            placeholder="滴速"
                          ></el-input>
                          <el-autocomplete
                            class="use-info-input"
                            v-model="shuye.remark.ds_unit"
                            placeholder="单位"
                            :fetch-suggestions="dsQuerySearch"
                            :trigger-on-focus="true"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            @select="
                              (val) => {
                                dsHandleSelect(val, index, shuyeidx);
                              }
                            "
                          >
                            <template slot-scope="{ item }">
                              <div class="useage-item">
                                <div class="name">
                                  <span>{{ item }}</span>
                                </div>
                              </div>
                            </template>
                          </el-autocomplete>
                        </div>
                      </td>
                      <td class="table-td" align="center">用药频率</td>
                      <td class="table-td">
                        <el-autocomplete
                          class="use-info-input"
                          v-model="shuye.remark.yypl"
                          :fetch-suggestions="syplQuerySearch"
                          placeholder="用药频率"
                          :trigger-on-focus="true"
                          @change="
                            (val) => {
                              syRemarkChange(val, index, shuyeidx);
                            }
                          "
                          @select="
                            (val) => {
                              syplHandleSelect(val, index, shuyeidx);
                            }
                          "
                        >
                          <template slot-scope="{ item }">
                            <div class="useage-item">
                              <div class="name">
                                <span>{{ item }}</span>
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </td>
                    </tr>
                    <tr class="table-td">
                      <td class="table-td" align="center">起始日期</td>
                      <td class="table-td" colspan="3">
                        <div>
                          <el-date-picker
                            v-model="shuye.remark.qzrq"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-ddTHH:mm:ss.000Z"
                            :picker-options="startTimeOptions"
                          >
                          </el-date-picker>
                        </div>
                      </td>
                      <td class="table-td" align="center">连续天数</td>
                      <td class="table-td">
                        <div class="jishu">
                          <el-input
                            v-model="shuye.remark.lxts"
                            @change="
                              (val) => {
                                syRemarkChange(val, index, shuyeidx);
                              }
                            "
                            placeholder="天数"
                          ></el-input>
                        </div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <el-form
                :model="shuye"
                ref="yinpianValidateForm"
                label-width="100px"
                class="injection-dynamic shuye-injection-dynamic"
              >
                <el-form-item
                  class="form-item-detail"
                  v-for="(domain, idx) in shuye.details"
                  :key="domain.key || idx"
                  :prop="'details.' + idx + '.value'"
                >
                  <div class="item-detail-main">
                    <div class="form-item-left">
                      <el-autocomplete
                        class="product-name-input"
                        v-model="domain.product_name"
                        :fetch-suggestions="syProQuerySearch"
                        placeholder="请输入药品名称"
                        :trigger-on-focus="false"
                        @focus="addShuyeItem(index, shuyeidx, idx)"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'product'
                            );
                          }
                        "
                        @select="
                          (item) => {
                            syProHandleSelect(item, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template
                          slot="suffix"
                          v-if="domain.own ? false : true"
                        >
                          <el-tooltip
                            v-if="domain.product_name !== ''"
                            content="该药品不在您的药库中，建议您更换其他药品"
                            placement="bottom"
                            effect="light"
                          >
                            <i class="el-icon-warning"> </i>
                          </el-tooltip>
                        </template>
                        <template slot-scope="{ item }">
                          <div
                            class="product-item-container"
                            style="
                              display: flex;
                              justify-content: flex-start;
                              align-items: flex-start;
                            "
                          >
                            <div
                              class="icon-container"
                              style="margin-right: 5px"
                            >
                              <i
                                class="el-icon-success"
                                style="color: green"
                                v-if="item.Own"
                              ></i>
                              <i class="el-icon-warning" v-else></i>
                            </div>
                            <div class="product-item" style="padding: 5px 0px">
                              <div
                                class="name"
                                style="font-weight: bold; line-height: 22px"
                              >
                                <span class="name-name">{{
                                  item.product_name
                                }}</span
                                ><span class="name-pack"
                                  >({{ item.pack }})</span
                                >
                              </div>
                              <div
                                class="producer"
                                style="color: #999; line-height: 22px"
                              >
                                <span>{{ item.production }}</span>
                              </div>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <el-input
                        class="num-input"
                        v-model="domain.single_dose"
                        oninput ="this.value=this.value.match(/\d+\.?\d{0,2}/)"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'single_dose'
                            );
                          }
                        "
                        placeholder="剂量"
                      ></el-input>
                      <el-autocomplete
                        class="inline-input"
                        v-model="domain.single_unit"
                        :fetch-suggestions="singleUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'single_unit'
                            );
                          }
                        "
                        @select="
                          (val) => {
                            sySingleUnitHandleSelect(val, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <el-input
                        class="num-input"
                        v-model="domain.skin_test"
                        @change="
                          (val) => {
                            syDetailChange(
                              val,
                              index,
                              shuyeidx,
                              idx,
                              'skin_test'
                            );
                          }
                        "
                        placeholder="皮试"
                      ></el-input>
                      <el-input
                        class="num-input"
                        v-model.number="domain.number"
                        oninput ="value=value.replace(/[^0-9.]/g,'')"
                        placeholder="开药量"
                        @change="
                          (val) => {
                            syDetailChange(val, index, shuyeidx, idx, 'number');
                          }
                        "
                        @keyup.native="
                          (val) => {
                            syNumberChange(val, index, shuyeidx, idx);
                          }
                        "
                      ></el-input>
                      <el-autocomplete
                        class="inline-input"
                        v-model="domain.unit"
                        :fetch-suggestions="numberUnitQuerySearch"
                        placeholder="单位"
                        :trigger-on-focus="true"
                        @change="
                          (val) => {
                            syDetailChange(val, index, shuyeidx, idx, 'unit');
                          }
                        "
                        @select="
                          (val) => {
                            syNumberUnitHandleSelect(val, index, shuyeidx, idx);
                          }
                        "
                      >
                        <template slot-scope="{ item }">
                          <div class="useage-item">
                            <div class="name">
                              <span>{{ item }}</span>
                            </div>
                          </div>
                        </template>
                      </el-autocomplete>
                      <div class="price" style="text-align: center">
                        <span>￥{{ domain.amount | moneyFormat }}</span>
                      </div>
                    </div>
                    <div class="btn">
                      <el-button
                        class="icon-btn"
                        icon="el-icon-delete"
                        @click.prevent="
                          removeShuyeItem(domain, index, shuyeidx, idx)
                        "
                      ></el-button>
                    </div>
                  </div>
                  <div class="item-details-info" v-if="domain.own">
                    <span
                      v-if="
                        domain.number > domain.stock &&
                        domain.product_name !== ''
                      "
                      class="info-tip"
                      >当前药品{{
                        domain.stock <= 0
                          ? "库存不足"
                          : `仅剩余${domain.stock}${domain.unit}`
                      }}，建议您更换其他药品</span
                    >
                  </div>
                </el-form-item>
              </el-form>
              <div class="add-item-line">
                <el-button
                  type="text"
                  @click="addShuyeItem(index, shuyeidx, -1)"
                  >添加药品</el-button
                >
              </div>
            </div>
          </div>
        </template>
      </div>
    </div>
    <!-- 附加费用 -->
    <div class="prescription-prescription-container surcharge-container">
      <div class="prescription-title">
        <div class="title-left"><span>附加费用</span></div>
        <div class="btn-right">
          <el-button style="min-width: 70px" @click="addSurcharge"
            >添加</el-button
          >
        </div>
      </div>
      <div
        class="prescription-content"
        v-if="surchargeList.length || payedSurchargeList.length"
      >
        <div
          class="prescription-payed-container"
          :class="surchargeList.length ? 'payed-split-line' : ''"
          v-if="payedSurchargeList.length"
        >
          <div class="pay-icon">
            <img
              src="../../../assets/img/payOrDrug/image_pay.png"
              alt=""
              srcset=""
            />
          </div>
          <el-form
            ref="surchargeForm"
            label-width="100px"
            class="injection-dynamic"
          >
            <el-form-item
              v-for="(surcharge, index) in payedSurchargeList"
              :key="index"
              :prop="'details.' + index + '.value'"
            >
              <div class="surchange-item-left">
                <el-autocomplete
                  class="surcharge-name-input"
                  v-model="surcharge.surcharge_name"
                  :fetch-suggestions="surchargeQuerySearch"
                  placeholder="请输入附加项"
                  :trigger-on-focus="false"
                  @keyup.native="
                    (val) => {
                      surchargeChange(val, 'suritem', index);
                    }
                  "
                  @select="
                    (item) => {
                      surchargeHandleSelect(item, index);
                    }
                  "
                >
                  <template slot-scope="{ item }">
                    <div class="product-item">
                      <div class="name">
                        <span>{{ item.cost_dict_name }}</span>
                      </div>
                    </div>
                  </template>
                </el-autocomplete>
                <div class="price" style="text-align: center">
                  <span>￥</span>
                  <el-input
                    class="price-inpu"
                    placeholder="0.00"
                    v-model="surcharge.amount"
                    @keyup.native="
                      (val) => {
                        surchargeChange(val, 'num', index);
                      }
                    "
                  ></el-input>
                </div>
              </div>
              <div class="btn">
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printCheckItem(surcharge, 2)"
                  ></el-button>
                </el-tooltip>
              </div>
            </el-form-item>
          </el-form>
        </div>
        <div class="prescription-nopay-container" v-if="surchargeList.length">
          <el-form
            ref="surchargeForm"
            label-width="100px"
            class="injection-dynamic"
          >
            <el-form-item
              v-for="(surcharge, index) in surchargeList"
              :key="index"
              :prop="'details.' + index + '.value'"
            >
              <div class="surchange-item-left">
                <el-autocomplete
                  class="surcharge-name-input"
                  v-model="surcharge.surcharge_name"
                  :fetch-suggestions="surchargeQuerySearch"
                  placeholder="请输入附加项"
                  :trigger-on-focus="false"
                  @keyup.native="
                    (val) => {
                      surchargeChange(val, 'suritem', index);
                    }
                  "
                  @select="
                    (item) => {
                      surchargeHandleSelect(item, index);
                    }
                  "
                >
                  <template slot-scope="{ item }">
                    <div class="product-item">
                      <div class="name">
                        <span>{{ item.cost_dict_name }}</span>
                      </div>
                    </div>
                  </template>
                </el-autocomplete>
                <div class="price" style="text-align: center">
                  <span>￥</span>
                  <el-input
                    class="price-inpu"
                    placeholder="0.00"
                    v-model="surcharge.amount"
                    oninput="value=value.replace(/^\.+|[^\d.]/g,'')"
                    @keyup.native="
                      (val) => {
                        surchargeChange(val, 'num', index);
                      }
                    "
                  ></el-input>
                </div>
              </div>

              <div class="btn">
                <el-tooltip content="打印" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-printer"
                    @click="printCheckItem(surcharge, 2)"
                  ></el-button>
                </el-tooltip>
                <el-tooltip content="删除" placement="bottom" effect="light">
                  <el-button
                    class="icon-btn"
                    icon="el-icon-delete"
                    @click.prevent="removeSurcharge(surcharge, index)"
                  ></el-button>
                </el-tooltip>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <div class="medicalAdvice-content-container">
      <div class="medicalAdvice-content">
        <div class="left-container">
          <div class="left-title"><span class="title">医嘱事项</span></div>
          <div class="input-container">
            <el-autocomplete
              class="inline-input"
              v-model="advice"
              :fetch-suggestions="querySearch"
              placeholder="请输入医嘱事项"
              :trigger-on-focus="false"
              @select="handleSelect"
            >
            </el-autocomplete>
          </div>
        </div>
        <div class="right-container">
          <el-button @click="selectAdvice">选择</el-button>
        </div>
      </div>
    </div>
    <div class="prescription-total-price-container">
      <div class="prescription-total-price">
        <div class="right-container">
          <span class="price-title">合计金额：</span>
          <span class="price-num">￥{{ totalPrice | moneyFormat }}</span>
        </div>
      </div>
    </div>
    <!-- 选择常用处方 -->
    <common-prescription
      ref="commonPrescription"
      @selectList="selectList"
    ></common-prescription>
    <!-- 存为常用处方 -->
    <el-dialog
      title="存为常用处方"
      width="30%"
      :close-on-click-modal="false"
      :visible.sync="dialogSavePres"
      v-if="dialogSavePres"
    >
      <el-form
        ref="saveCommonForm"
        :model="saveCommonPres"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="处方名称" prop="prescription_name">
          <el-input
            v-model="saveCommonPres.prescription_name"
            placeholder="请输入处方名称"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="border-btn" @click="closeDialogSavePres"
          >取 消</el-button
        >
        <el-button class="main-btn" type="primary" @click="confirmSavePres"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 选择常用医嘱 -->
    <common-advice
      ref="commonAdvice"
      @selectAdviceList="selectAdviceList"
    ></common-advice>
  </div>
</template>
<script>
import commonPrescription from "./commonPrescription";
import commonAdvice from "./commonAdvice";
import { productSearch, productDetail } from "@/api/product.js";
import { checkTreatment } from "@/api/prescription.js";
import publicRemind from "@/assets/js/publicRemind.js";
import { prescriptionCreate, prescriptionEdit } from "@/api/templates.js";

export default {
  components: {
    commonPrescription,
    commonAdvice,
  },
  data() {
    return {
      dialogSavePres: false,
      saveCommonPres: null,
      remindData: publicRemind.remind,
      advice: "",
      checkItemsForm: {
        price_amount: 0,
        check_items: [],
      },
      payedCheckItems: [],
      checkItemQueryList: [],
      surchargeQueryList: [],
      delete_items: {
        check_ids: [],
        pre_ids: [],
        sur_ids: [],
      },
      chengyaoList: [],
      yinpianList: [],
      shuyeList: [],
      surchargeList: [],
      payedSurchargeList: [],
      payedChengyaoList: [],
      payedYinpianList: [],
      payedShuyeList: [],
      restaurants: [],
      cyProductList: [], // 成药联想数据
      ypProductList: [], // 饮片联想数据
      startTimeOptions: {
        disabledDate(time) {
          //此条为设置禁止用户选择今天之前的日期，包含今天。
          return time.getTime() <= Date.now() - 8.64e7;
        },
      },
      prescriptionBtnShowList: [],
      rules: {
        prescription_name: {
          required: true,
          message: "处方名称不能为空",
          trigger: "blur",
        },
      },
    };
  },

  computed: {
    totalPrice() {
      this.checkItemsForm.price_amount = 0;
      this.checkItemsForm.check_items.forEach((checkitem, checkidx) => {
        checkitem.amount =
          Number(checkitem.price) * Number(checkitem.check_item_number);
        this.checkItemsForm.price_amount += checkitem.amount;
      });
      // 未支付的成药总价
      let cyTotalPrice = 0;
      this.chengyaoList.forEach((cy, cyidx) => {
        cy.price_amount = 0;
        cy.details.forEach((det, detidx) => {
          cy.price_amount += Number(det.price) * Number(det.number);
        });
        cyTotalPrice += cy.price_amount;
      });
      // 已支付的成药总价
      let cyPayedTotalPrice = 0;
      this.payedChengyaoList.forEach((cy, cyidx) => {
        cy.price_amount = 0;
        if (cy.details) {
          cy.details.forEach((det, detidx) => {
            cy.price_amount += Number(det.price) * Number(det.number);
          });
          cyPayedTotalPrice += cy.price_amount;
        }
      });
      // 未支付的饮片总价
      let ypTotalPrice = 0;
      this.yinpianList.forEach((yp, cyidx) => {
        yp.price_amount = 0;
        yp.details.forEach((det, detidx) => {
          yp.price_amount += Number(det.price) * Number(det.number);
        });
        ypTotalPrice += yp.price_amount;
      });
      // 已支付的饮片总价
      let ypPayedTotalPrice = 0;
      this.payedYinpianList.forEach((yp, cyidx) => {
        yp.price_amount = 0;
        if (yp.details) {
          yp.details.forEach((det, detidx) => {
            yp.price_amount += Number(det.price) * Number(det.number);
          });
          ypPayedTotalPrice += yp.price_amount;
        }
      });
      // 未支付的输液处方总价
      let syTotalPrice = 0;
      this.shuyeList.forEach((sy, cyidx) => {
        sy.price_amount = 0;
        if (sy.group) {
          sy.group.forEach((gr, gridx) => {
            let groupPrice = 0;
            if (gr.details) {
              gr.details.forEach((det, detidx) => {
                det.amount = Number(det.price) * Number(det.number);
                groupPrice += det.amount;
              });
              sy.price_amount += groupPrice;
            }
          });
          syTotalPrice += sy.price_amount;
        }
      });
      // 支付的输液处方总价
      let syPayedTotalPrice = 0;
      this.payedShuyeList.forEach((sy, cyidx) => {
        sy.price_amount = 0;
        if (sy.group) {
          sy.group.forEach((gr, gridx) => {
            let groupPrice = 0;
            if (gr.details) {
              gr.details.forEach((det, detidx) => {
                det.amount = Number(det.price) * Number(det.number);
                groupPrice += det.amount;
              });
              sy.price_amount += groupPrice;
            }
          });
          syPayedTotalPrice += sy.price_amount;
        }
      });
      // 未支付附加费用
      let surPayedTotalPrice = 0;
      this.surchargeList.forEach((sur, suridx) => {
        surPayedTotalPrice += Number(sur.amount);
      });

      // 已支付附加费用
      let surTotalPrice = 0;
      this.payedSurchargeList.forEach((sur, suridx) => {
        surTotalPrice += Number(sur.amount);
      });
      console.log(this.shuyeList);
      let totalPriceCount =
        this.checkItemsForm.price_amount +
        cyTotalPrice +
        cyPayedTotalPrice +
        ypTotalPrice +
        ypPayedTotalPrice +
        syTotalPrice +
        syPayedTotalPrice +
        surTotalPrice +
        surPayedTotalPrice;
      return totalPriceCount;
    },
  },
  mounted() {
    this.restaurants = this.loadAll();
    this.prescriptionBtnShow();

    this.getCheckQuery();
    this.getSurchargeQuery();
    console.log(this.payedShuyeList);
  },
  methods: {
    selectList(list) {
      this.selectListHandle(list);
    },
    selectListHandle(listdata) {
      if (listdata && listdata.length > 0) {
        listdata.forEach((item, index) => {
          if (item.prescription.category_key == "cycf") {
            item.prescription.template_id = item.ID;
            item.prescription.user_id = item.user_id; // 用于判断是诊所还是个人
            item.prescription.update_status = 2;
            this.chengyaoList.push(item.prescription);
          } else if (item.prescription.category_key == "ypcf") {
            item.prescription.template_id = item.ID;
            item.prescription.user_id = item.user_id; // 用于判断是诊所还是个人
            item.prescription.update_status = 2;
            item.prescription.remark = item.prescription.remark[1];
            this.yinpianList.push(item.prescription);
          } else if (item.prescription.category_key == "sycf") {
            let syItem = {
              ID: item.prescription.ID,
              template_id: item.ID,
              user_id: item.user_id, // 用于判断是诊所还是个人
              update_status: 2,
              prescription_name: "",
              category_key: "sycf",
              category_name: "输液处方",
              prescription_status: item.prescription.prescription_status,
              group: [],
            };
            for (const key in item.prescription.remark) {
              item.prescription.remark[key].qzrq = new Date(); // 起始日期默认当天
              let gitem = {
                price_amount: 0,
                details: [],
                remark: {},
              };
              let list = item.prescription.details.filter(
                (p) => p.group == Number(key)
              );
              list.forEach((g, gi) => {
                gitem.price_amount += g.amount;
              });
              gitem.details = list;
              gitem.remark = item.prescription.remark[key];

              syItem.group.push(gitem);
            }

            this.shuyeList.push(syItem);
          }
        });
      }
    },
    // 存为常用处方
    saveCommonPrescription(presItem) {
      this.saveCommonPres = presItem;
      // 数据为空时不能存
      let bool = true;
      if (
        this.saveCommonPres.category_key == "cycf" ||
        this.saveCommonPres.category_key == "ypcf"
      ) {
        if (this.saveCommonPres.details) {
          bool = this.saveCommonPres.details.some((p) => p.product_name !== "");
        }
      } else {
        if (this.saveCommonPres.group) {
          bool = this.saveCommonPres.group.some((p) =>
            p.details.some((h) => h.product_name !== "")
          );
        }
      }
      if (!bool) {
        this.$message({
          type: "warning",
          message: "请完善处方信息",
          duration: 1000,
        });
      } else {
        this.dialogSavePres = true;
      }
      console.log(this.saveCommonPres);
    },
    closeDialogSavePres() {
      this.dialogSavePres = false;
    },
    confirmSavePres() {
      var that = this;
      this.$refs.saveCommonForm.validate((valid) => {
        if (valid) {
          let subItem = {
            ID: 0,
            template_id: that.saveCommonPres.template_id || 0,
            user_id: 0,
            update_status: that.saveCommonPres.update_status,
            prescription_name: that.saveCommonPres.prescription_name,
            category_key: "",
            category_name: "",
            details: [],
            remark: null,
          };
          if (that.saveCommonPres.category_key == "cycf") {
            let detail = JSON.parse(
              JSON.stringify(that.saveCommonPres.details)
            );
            let detailList = [];
            detail.forEach((m, i) => {
              m.number = Number(m.number);
              m.price = Number(m.price);
              m.amount = Number(m.amount);
              if (m.product_name !== "" && m.product_name !== undefined) {
                detailList.push(m);
              }
            });
            subItem.user_id = that.saveCommonPres.user_id;
            subItem.category_key = "cycf";
            subItem.category_name = "成药处方";
            subItem.details = detailList;
            subItem.group_count = 1;
          }
          if (that.saveCommonPres.category_key == "ypcf") {
            let detail = JSON.parse(
              JSON.stringify(that.saveCommonPres.details)
            );
            let detailList = [];
            detail.forEach((m, i) => {
              m.number = Number(m.number);
              m.price = Number(m.price);
              m.amount = Number(m.amount);
              if (m.product_name !== "" && m.product_name !== undefined) {
                detailList.push(m);
              }
            });
            subItem.user_id = that.saveCommonPres.user_id;
            subItem.category_key = "ypcf";
            subItem.category_name = "饮片处方";
            subItem.details = detailList;
            subItem.remark = {
              1: that.saveCommonPres.remark,
            };
            subItem.group_count = 1;
          }
          if (that.saveCommonPres.category_key == "sycf") {
            subItem.remark = {};
            subItem.user_id = that.saveCommonPres.user_id;
            subItem.group_count = that.saveCommonPres.group.length;
            subItem.category_key = "sycf";
            subItem.category_name = "输液处方";
            that.saveCommonPres.group.forEach((gitm, gidx) => {
              let detail = JSON.parse(JSON.stringify(gitm.details));
              let detailList = [];
              detail.forEach((m, i) => {
                m.number = Number(m.number);
                m.price = Number(m.price);
                m.amount = Number(m.amount);
                m.group = gidx + 1;
                if (m.product_name !== "" && m.product_name !== undefined) {
                  detailList.push(m);
                }
              });
              subItem.details = detailList;
              Object.assign(subItem.remark, { [gidx + 1]: gitm.remark });
            });
          }
          let submitData = {
            template_name: that.saveCommonPres.prescription_name,
            pre_type: 1,
            prescription: subItem,
          };

          if (subItem.template_id) {
            if (subItem.user_id) {
              submitData.id = subItem.template_id;
              that.prescriptionEditFun(submitData);
            } else {
              submitData.id = 0;
              that.prescriptionCreateFun(submitData);
            }
          } else {
            that.prescriptionCreateFun(submitData);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    prescriptionEditFun(datas) {
      prescriptionEdit(datas).then((res) => {
        if (res.code == 200) {
          console.log("存成功");
          this.dialogSavePres = false;
          this.$message({
            type: "success",
            message: "保存成功",
            duration: 1000,
          });
        }
      });
    },
    prescriptionCreateFun(datas) {
      prescriptionCreate(datas).then((res) => {
        if (res.code == 200) {
          console.log("创建成功");
          this.dialogSavePres = false;
          this.$message({
            type: "success",
            message: "保存成功",
            duration: 1000,
          });
        }
      });
    },
    // 选择常用医嘱
    // 打开常用医嘱选择框
    selectAdvice() {
      this.$refs.commonAdvice.openCommonList();
    },
    // 拿到选择的医嘱
    selectAdviceList(list) {
      let adv = list.map((val) => {
        return val.contents;
      });
      if (adv.length) {
        this.advice = adv.toString();
      } else {
        this.advice = "";
      }
    },
    prescriptionBtnShow() {
      this.prescriptionBtnShowList = this.$store.getters.userHabit.checkTypeList;
    },
    printItemClick(patentMedicine) {
      if (
        patentMedicine.update_status !== 1 &&
        patentMedicine.update_status !== 2
      ) {
        this.$emit("printItemClick", patentMedicine);
      } else {
        this.$message({
          type: "error",
          message: "请先进行保存",
          duration: 1000,
        });
      }
    },
    printCheckItem(item, type) {
      // type区分打印检查项还是附加费用
      if (item.update_status !== 1 && item.update_status !== 2) {
        item.type = type;
        this.$emit("printCheckItemClick", item);
      } else {
        this.$message({
          type: "error",
          message: "请先进行保存",
          duration: 1000,
        });
      }
    },
    getCheckQuery() {
      checkTreatment({ type: 1 }).then((res) => {
        if (res.code == 200) {
          this.checkItemQueryList = res.data || [];
        }
      });
    },
    getSurchargeQuery() {
      checkTreatment({ type: 2 }).then((res) => {
        if (res.code == 200) {
          this.surchargeQueryList = res.data || [];
        }
      });
    },
    // 处理并返回处方数据
    emitPrescriptionData() {
      return {
        check_items: this.checkItemsForm.check_items,
        chengyaoList: this.chengyaoList,
        yinpianList: this.yinpianList,
        shuyeList: this.shuyeList,
        payedChengyaoList: this.payedChengyaoList,
        payedYinpianList: this.payedYinpianList,
        payedShuyeList: this.payedShuyeList,
        surchargeList: this.surchargeList,
        payedSurchargeList: this.payedSurchargeList,
        advice: this.advice,
        delete_items: this.delete_items,
      };
    },
    //  检查项
    removeCheckItem(item) {
      var index = this.checkItemsForm.check_items.indexOf(item);
      if (index !== -1) {
        this.checkItemsForm.check_items.splice(index, 1);
        this.delete_items.check_ids.push(item.ID);
      }
    },
    addCheckItem() {
      this.checkItemsForm.check_items.push({
        ID: 0,
        own: true,
        update_status: 2,
        check_item_name: "",
        check_item_number: 1,
        check_item_status: 1, // 未收费
        price: 0,
        amount: 0,
        key: Date.now(),
      });
    },
    // 添加附加项
    addSurcharge() {
      this.surchargeList.push({
        ID: 0,
        own: true,
        update_status: 2,
        surcharge_name: "",
        surcharge_status: 1,
        cost_price: 0,
        amount: 0,
      });
    },
    // 删除附加项
    removeSurcharge(item) {
      var index = this.surchargeList.indexOf(item);
      if (index !== -1) {
        this.surchargeList.splice(index, 1);
        this.delete_items.sur_ids.push(item.ID);
      }
    },
    surchargeChange(val, type, index) {
      console.log(this.surchargeList[index].amount);
      if (this.surchargeList[index].update_status !== 2) {
        this.surchargeList[index].update_status = 1;
      }

      if (val.keyCode !== 13) {
        if (type == "suritem") {
          this.surchargeList[index].cost_price = 0;
          this.surchargeList[index].amount = 0;
        }
      }
      // if (type == "num") {
      //   this.surchargeList[index].cost_price = Number(val.key);
      //   this.surchargeList[index].amount = Number(val.key);
      // }
    },
    // 创建成药处方
    addPatentMedicine() {
      let cyItem = {
        ID: 0,
        update_status: 2,
        prescription_name: "",
        category_key: "cycf",
        category_name: "成药处方",
        prescription_status: 1,
        price_amount: 0,
        details: [
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            use_way: "", // 用法
            medication_rate: "", // 用药频率
            single_dose: "", // 单次剂量
            single_unit: "", // 单次剂量
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
          },
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            use_way: "", // 用法
            medication_rate: "", // 用药频率
            single_dose: "", // 单次剂量
            single_unit: "", // 单次剂量
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
          },
        ],
      };
      this.chengyaoList.push(cyItem);
    },
    // 删除成药处方
    removePatentMedicineItem(index) {
      let delID = this.chengyaoList[index].ID;
      this.chengyaoList.splice(index, 1);
      this.delete_items.pre_ids.push(delID);
    },
    // 成药处方行
    removePatentItem(item, index, idx) {
      //   var index = this.chengyaoList[index].details.indexOf(item);
      //   if (index !== -1) {
      //     this.chengyaoList[index].details.splice(idx, 1);
      //   }
      this.chengyaoList[index].details.splice(idx, 1);
      this.chengyaoList[index].update_status = 1;
      // 如果药品全部删除，整个处方删除
      if (this.chengyaoList[index].details.length == 0) {
        this.delete_items.pre_ids.push(this.chengyaoList[index].ID);
        this.chengyaoList.splice(index, 1);
      }
    },
    // 添加成药处方行
    addPatentItem(index, idx) {
      if (idx == this.chengyaoList[index].details.length - 1) {
        this.chengyaoList[index].details.push({
          own: true,
          product_id: 0,
          product_name: "",
          pack: "", // 规格
          use_way: "", // 用法
          medication_rate: "", // 用药频率
          single_dose: "", // 用药频率
          single_unit: "", // 单次剂量
          number: "", // 数量
          price: 0, // 价格
          amount: 0, // 总价
          unit: "",
          group: 1,
          key: Date.now(),
        });
      }
    },

    // 创建饮片处方
    addYinpian() {
      let ypItem = {
        ID: 0,
        update_status: 2,
        prescription_name: "",
        category_key: "ypcf",
        category_name: "饮片处方",
        prescription_status: 1,
        price_amount: 0,
        remark: {
          js: "",
          mrjl: "",
          yypl: "",
          yf: "",
          fyyq: "",
        },
        details: [
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
            remark: "",
          },
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
            remark: "",
          },
        ],
      };

      this.yinpianList.push(ypItem);
    },
    // 删除成药处方
    removeYinpian(index) {
      let delID = this.yinpianList[index].ID;
      this.yinpianList.splice(index, 1);
      this.delete_items.pre_ids.push(delID);
    },
    // 成药处方行
    removeYinpianItem(item, index, idx) {
      //   var index = this.yinpianList[index].details.indexOf(item);
      //   if (index !== -1) {
      //     this.yinpianList[index].details.splice(idx, 1);
      //   }
      this.yinpianList[index].details.splice(idx, 1);
      this.yinpianList[index].update_status = 1;
      if (this.yinpianList[index].details.length == 0) {
        this.delete_items.pre_ids.push(this.yinpianList[index].ID);
        this.yinpianList.splice(index, 1);
      }
    },
    // 添加成药处方行
    addYinpinItem(index, idx) {
      if (idx == this.yinpianList[index].details.length - 1) {
        this.yinpianList[index].details.push({
          own: true,
          product_id: 0,
          product_name: "",
          pack: "", // 规格
          number: "", // 数量
          price: 0, // 价格
          amount: 0, // 总价
          unit: "",
          group: 1,
          remark: "",
          key: Date.now(),
        });
      }
    },
    // 输液处方开始
    // 添加输液处方
    addTransfuse() {
      let items = {
        ID: 0,
        update_status: 2,
        prescription_name: "",
        category_key: "sycf",
        category_name: "输液处方",
        prescription_status: 1,
        group: [
          {
            price_amount: 0,
            remark: {
              yf: "",
              yypl: "",
              ds: "",
              ds_unit: "",
              qzrq: new Date(),
              lxts: "",
            },
            details: [
              {
                own: true,
                product_id: 0,
                product_name: "",
                pack: "", // 规格
                single_dose: "", // 单次剂量
                single_unit: "", // 单次剂量
                skin_test: "", // 皮试
                number: "", // 数量
                price: 0, // 价格
                amount: 0, // 总价
                unit: "",
                group: 1,
              },
              {
                own: true,
                product_id: 0,
                product_name: "",
                pack: "", // 规格
                single_dose: "", // 单次剂量
                single_unit: "", // 单次剂量
                skin_test: "", // 皮试
                number: "", // 数量
                price: 0, // 价格
                amount: 0, // 总价
                unit: "",
                group: 1,
              },
            ],
          },
        ],
      };
      this.shuyeList.push(items);
    },
    // 删除输液
    removeShuye(index) {
      let delID = this.shuyeList[index].ID;
      this.shuyeList.splice(index, 1);
      this.delete_items.pre_ids.push(delID);
    },
    addShuyeGroup(index, shuyeidx) {
      let group = {
        price_amount: 0,
        remark: {
          yf: "",
          yypl: "",
          ds: "",
          ds_unit: "",
          qzrq: new Date(),
          lxts: "",
        },
        details: [
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            single_dose: "", // 单次剂量
            single_unit: "", // 单次剂量
            skin_test: "", // 皮试
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
          },
          {
            own: true,
            product_id: 0,
            product_name: "",
            pack: "", // 规格
            single_dose: "", // 单次剂量
            single_unit: "", // 单次剂量
            skin_test: "", // 皮试
            number: "", // 数量
            price: 0, // 价格
            amount: 0, // 总价
            unit: "",
            group: 1,
          },
        ],
      };
      this.shuyeList[index].group.push(group);
      this.shuyeList[index].update_status = 1;
    },
    removeShuyeGroup(index, shuyeidx) {
      this.shuyeList[index].update_status = 1;
      this.shuyeList[index].group.splice(shuyeidx, 1);
    },
    // 添加输液处方行
    addShuyeItem(index, shuyeidx, idx) {
      if (
        idx == -1 ||
        idx == this.shuyeList[index].group[shuyeidx].details.length - 1
      ) {
        this.shuyeList[index].group[shuyeidx].details.push({
          own: true,
          product_id: 0,
          product_name: "",
          pack: "", // 规格
          single_dose: "", // 用药频率
          single_unit: "", // 单次剂量
          skin_test: "", // 皮试
          number: "", // 数量
          price: 0, // 价格
          amount: 0, // 总价
          unit: "",
          group: 1,
        });
        if(this.shuyeList[index].update_status!==2){
          this.shuyeList[index].update_status = 1;
        }
      }
    },
    // 输液用法输入联想--开始
    syyfQuerySearch(queryString, cb) {
      var restaurants = this.remindData.shuye_usage;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    syyfHandleSelect(val, index, shuyeidx) {
      this.shuyeList[index].group[shuyeidx].remark.yf = val;
    },
    // 删除输液处方行
    removeShuyeItem(item, index, shuyeidx, idx) {
      this.shuyeList[index].group[shuyeidx].details.splice(idx, 1);
      this.shuyeList[index].update_status = 1;
      if (this.shuyeList[index].group[shuyeidx].details.length == 0) {
        this.shuyeList[index].group.splice(shuyeidx, 1);
      }
      if (this.shuyeList[index].group.length == 0) {
        this.delete_items.pre_ids.push(this.shuyeList[index].ID);
        this.shuyeList.splice(index, 1);
      }
    },
    // 用法选择
    syyfHandleSelect(val, index, shuyeidx) {
      this.shuyeList[index].group[shuyeidx].remark.yf = val;
    },
    // 输液用药频率输入联想--开始
    syplQuerySearch(queryString, cb) {
      var restaurants = this.remindData.eat_rate;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    syplHandleSelect(val, index, shuyeidx) {
      this.shuyeList[index].group[shuyeidx].remark.yypl = val;
    },
    // 滴速输入联想
    dsQuerySearch(queryString, cb) {
      var restaurants = this.remindData.ds_unit;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    dsHandleSelect(val, index, shuyeidx) {
      this.shuyeList[index].group[shuyeidx].remark.ds_unit = val;
    },
    syRemarkChange(val, index, shuyeidx) {
      if (this.shuyeList[index].update_status !== 2) {
        this.shuyeList[index].update_status = 1;
      }
    },
    syDetailChange(val, index, shuyeidx, idx, type) {
      if (type == "product") {
        this.shuyeList[index].group[shuyeidx].details[idx].own = false;
      }
      if (type == "number") {
        if(Number(val)<=0){
          this.shuyeList[index].group[shuyeidx].details[idx].number = 1;
          this.shuyeList[index].group[shuyeidx].details[idx].amount = this.shuyeList[index].group[shuyeidx].details[idx].price;
        }
      }
      if (this.shuyeList[index].update_status !== 2) {
        this.shuyeList[index].update_status = 1;
      }
    },
    // 输液处方结束
    // 常用处方
    addCommonlyPrescription() {
      this.$refs.commonPrescription.openCommonList();
    },
    getProductSearch() {
      productSearch().then((res) => {
        if (res.code == 200) {
          return res.data;
        }
      });
    },
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    thinkListHandle(data) {
      if (data.ElasticProduct && data.ElasticProduct) {
        data.ElasticProduct.forEach((item, index) => {
          item.Own = data.self;
        });
      }
      return data.ElasticProduct || [];
    },
    // 成药产品联想
    async cyQuerySearch(queryString, cb) {
      let pro = await productSearch({
        prefix: queryString,
        size: 40,
        condition: {
          category_id: "2",
        },
      });
      this.cyProductList = this.thinkListHandle(pro.data);
      var results = this.cyProductList;
      cb(results);
    },
    // 饮片产品联想
    async ypQuerySearch(queryString, cb) {
      let pro = await productSearch({
        prefix: queryString,
        size: 40,
        condition: {
          category_id: "1",
        },
      });
      this.ypProductList = this.thinkListHandle(pro.data);
      var results = this.ypProductList;
      cb(results);
    },
    // 输液产品联想
    async syProQuerySearch(queryString, cb) {
      let pro = await productSearch({ prefix: queryString, size: 10 });
      this.syProductList = this.thinkListHandle(pro.data);
      var results = this.syProductList;
      cb(results);
    },
    commonCreateFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    // 用法输入联想--开始
    cyyfQuerySearch(queryString, cb) {
      var restaurants = this.remindData.xy_usage;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    usageHandleSelect(val, index, idx) {
      this.chengyaoList[index].details[idx].use_way = val;
    },
    // 用法输入联想--结束

    // 用药频率输入联想--开始
    medicationRateQuerySearch(queryString, cb) {
      var restaurants = this.remindData.eat_rate;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    medicationRateHandleSelect(val, index, idx) {
      this.chengyaoList[index].details[idx].medication_rate = val;
    },
    // 用药频率输入联想--结束

    // 剂量单位输入联想--开始
    singleUnitQuerySearch(queryString, cb) {
      var restaurants = this.remindData.dose_unit;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    singleUnitHandleSelect(val, index, idx) {
      this.chengyaoList[index].details[idx].single_unit = val;
    },
    sySingleUnitHandleSelect(val, index, shuyeidx, idx) {
      this.shuyeList[index].group[shuyeidx].details[idx].single_unit = val;
    },
    // 剂量单位输入联想--结束

    // 销售单位输入联想--开始
    numberUnitQuerySearch(queryString, cb) {
      var restaurants = this.remindData.number_unit;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    numberUnitHandleSelect(val, index, idx) {
      this.chengyaoList[index].details[idx].unit = val;
    },
    syNumberUnitHandleSelect(val, index, shuyeidx, idx) {
      this.shuyeList[index].group[shuyeidx].details[idx].unit = val;
    },
    // 销售单位输入联想--结束

    // 饮片联想
    async checkItemQuerySearch(queryString, cb) {
      // let pro = await checkTreatment({ type: 1 });
      let checkItemList = this.checkItemQueryList || [];
      let results = queryString
        ? checkItemList.filter(this.checkItemCreateFilter(queryString))
        : checkItemList;
      cb(results);
    },
    checkItemCreateFilter(queryString) {
      return (restaurant) => {
        let result =
          restaurant.cost_dict_name
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0 ||
          restaurant.all_spell
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0 ||
          restaurant.spell.toLowerCase().indexOf(queryString.toLowerCase()) ===
            0;
        return result;
      };
    },
    // 饮片用药频率输入联想--开始
    yyplQuerySearch(queryString, cb) {
      var restaurants = this.remindData.eat_rate;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    yyplHandleSelect(val, index) {
      this.yinpianList[index].remark.yypl = val;
    },
    // 饮片用药频率输入联想--结束

    // 饮片用法输入联想--开始
    yfQuerySearch(queryString, cb) {
      var restaurants = this.remindData.yinpian_useage;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    yfHandleSelect(val, index) {
      this.yinpianList[index].remark.yf = val;
    },
    // 饮片用法输入联想--结束

    // 服用要求输入联想--开始
    fyyqQuerySearch(queryString, cb) {
      var restaurants = this.remindData.require;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    fyyqHandleSelect(val, index) {
      this.yinpianList[index].remark.fyyq = val;
    },
    // 饮片用法输入联想--结束

    // 服用要求输入联想--开始
    remarkQuerySearch(queryString, cb) {
      var restaurants = this.remindData.advice;
      var results = queryString
        ? restaurants.filter(this.commonCreateFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    remarkHandleSelect(val, index, idx) {
      this.yinpianList[index].details[idx].remark = val;
    },
    // 饮片用法输入联想--结束

    // 附加费用
    async surchargeQuerySearch(queryString, cb) {
      // let pro = await checkTreatment({ type: 2 });
      let checkItemList = this.surchargeQueryList || [];
      let results = queryString
        ? checkItemList.filter(this.surchargeCreateFilter(queryString))
        : checkItemList;
      cb(results);
    },
    surchargeCreateFilter(queryString) {
      return (restaurant) => {
        let result =
          restaurant.cost_dict_name
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0 ||
          restaurant.all_spell
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) === 0 ||
          restaurant.spell.toLowerCase().indexOf(queryString.toLowerCase()) ===
            0;
        return result;
      };
    },
    // 检查项改变---改变更新状态
    checkItemChange(val, type, index) {
      console.log(val, type, index);
      if (type == "checkitem") {
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].own = false;
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].check_item_number = 1;
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].price = 0;
      }
      if (
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].update_status !== 2
      ) {
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].update_status = 1;
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].price = 0;
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].amount = 0;
      }
    },
    // 成药处方改变---改变更新状态
    cyChange(val, index, idx, type) {
      if (type == "product") {
        this.chengyaoList[index].details[idx].stock = 0;
        this.chengyaoList[index].details[idx].own = false;
        this.chengyaoList[index].details[idx].product_id = 0;
        this.chengyaoList[index].details[idx].production = "";
        this.chengyaoList[index].details[idx].pack = "";
        this.chengyaoList[index].details[idx].use_way = "";
        this.chengyaoList[index].details[idx].medication_rate = "";
        this.chengyaoList[index].details[idx].single_dose = "";
        this.chengyaoList[index].details[idx].single_unit = "";
        this.chengyaoList[index].details[idx].unit = "";
        this.chengyaoList[index].details[idx].price = 0;
        this.chengyaoList[index].details[idx].number = "";
        this.chengyaoList[index].details[idx].amount = 0;
      }
      if(type=="number"){
        if(Number(val)<=0){
          this.chengyaoList[index].details[idx].number = 1;
          this.chengyaoList[index].details[idx].amount = this.chengyaoList[index].details[idx].price
        }
      }
      if (this.chengyaoList[index].update_status !== 2) {
        this.chengyaoList[index].update_status = 1;
      }
    },
    // 饮片remark改变---改变更新状态
    ypRemarkChange(val, index) {
      if (this.yinpianList[index].update_status !== 2) {
        this.yinpianList[index].update_status = 1;
      }
    },
    // 饮片detail改变---改变更新状态
    ypDetailChange(val, index, idx, type) {
      if (type == "product") {
        this.yinpianList[index].details[idx].own = false;
      }
      if (type == "number") {
        if(Number(val)<=0){
          this.yinpianList[index].details[idx].number = 1;
          this.yinpianList[index].details[idx].amount = this.yinpianList[index].details[idx].price;
        }
      }
      if (this.yinpianList[index].update_status !== 2) {
        this.yinpianList[index].update_status = 1;
      }
    },
    loadAll() {
      return [
        { value: "三全鲜食（北新泾店）", address: "长宁区新渔路144号" },
        {
          value: "Hot honey 首尔炸鸡（仙霞路）",
          address: "上海市长宁区淞虹路661号",
        },
        {
          value: "新旺角茶餐厅",
          address: "上海市普陀区真北路988号创邑金沙谷6号楼113",
        },
        { value: "泷千家(天山西路店)", address: "天山西路438号" },
        {
          value: "胖仙女纸杯蛋糕（上海凌空店）",
          address: "上海市长宁区金钟路968号1幢18号楼一层商铺18-101",
        },
        { value: "贡茶", address: "上海市长宁区金钟路633号" },
        {
          value: "豪大大香鸡排超级奶爸",
          address: "上海市嘉定区曹安公路曹安路1685号",
        },
        {
          value: "茶芝兰（奶茶，手抓饼）",
          address: "上海市普陀区同普路1435号",
        },
        { value: "十二泷町", address: "上海市北翟路1444弄81号B幢-107" },
        { value: "星移浓缩咖啡", address: "上海市嘉定区新郁路817号" },
        { value: "阿姨奶茶/豪大大", address: "嘉定区曹安路1611号" },
        { value: "新麦甜四季甜品炸鸡", address: "嘉定区曹安公路2383弄55号" },
      ];
    },
    handleSelect(item) {
      console.log(item);
    },
    checkItemHandleSelect(item, index) {
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].own = true;
      // 赋值给没收费的index个
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].check_item_name = item.cost_dict_name;
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].price = Number(item.sell_price);
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].check_item_number = 1;
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].amount = 1 * Number(item.sell_price);
    },
    checkItemNumberChange(val, index) {
      if (
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].update_status !== 2
      ) {
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].update_status = 1;
      }
      let price = Number(
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].price
      );
      let num = Number(
        this.checkItemsForm.check_items.filter(
          (p) => p.check_item_status !== 2
        )[index].check_item_number
      );
      this.checkItemsForm.check_items.filter((p) => p.check_item_status !== 2)[
        index
      ].amount = price * num;
      console.log(this.checkItemsForm.check_items[index]);
      // this.$set(this.checkItemsForm.check_items[index],"amount",this.checkItemsForm.check_items[index].amount)
    },
    async cyProHandleSelect(item, index, idx) {
      console.log(item, index, idx);
      let product = await productDetail({ default_id: item.id });
      this.chengyaoList[index].details[idx].stock = product.data
        ? product.data.number
        : 0;
      this.chengyaoList[index].details[idx].product_id = product.data
        ? product.data.id
        : item.id;
      this.chengyaoList[index].details[idx].product_name = product.data
        ? product.data.product_name
        : item.product_name;
      this.chengyaoList[index].details[idx].production = product.data
        ? product.data.production
        : item.production;
      this.chengyaoList[index].details[idx].pack = product.data
        ? product.data.pack
        : item.pack;
      this.chengyaoList[index].details[idx].use_way = product.data
        ? product.data.usage
        : item.usage;
      this.chengyaoList[index].details[idx].medication_rate = product.data
        ? product.data.rate
        : item.rate;
      this.chengyaoList[index].details[idx].single_dose = product.data
        ? product.data.dose
        : item.dose;
      this.chengyaoList[index].details[idx].single_unit = product.data
        ? product.data.dose_unit
        : item.dose_unit;
      this.chengyaoList[index].details[idx].unit = product.data
        ? product.data.number_unit
        : item.number_unit;
      if (product.data) {
        if (product.data.number) {
          this.chengyaoList[index].details[idx].price = Number(
            product.data.price
          );
          this.chengyaoList[index].details[idx].own = true;
        } else {
          this.chengyaoList[index].details[idx].price = 0;
          this.chengyaoList[index].details[idx].own = false;
        }
      } else {
        this.chengyaoList[index].details[idx].price = 0;
        this.chengyaoList[index].details[idx].own = false;
      }
      this.chengyaoList[index].details[idx].number = product.data
        ? product.data.default_sell_number
        : 1;
      let price = this.chengyaoList[index].details[idx].price;
      let num = this.chengyaoList[index].details[idx].number;
      this.chengyaoList[index].details[idx].amount = price * num;
    },
    async cyNumberChange(val, index, idx) {
      let pro_id = this.chengyaoList[index].details[idx].product_id;
      let product = await productDetail({ product_id: pro_id });
      this.chengyaoList[index].details[idx].stock = product.data
        ? product.data.number
        : 0;
      let price = this.chengyaoList[index].details[idx].price;
      let num = this.chengyaoList[index].details[idx].number;
      this.chengyaoList[index].details[idx].amount = price * num;
    },
    async ypProHandleSelect(item, index, idx) {
      let product = await productDetail({ default_id: item.id });
      this.yinpianList[index].details[idx].stock = product.data
        ? product.data.number
        : 0;
      this.yinpianList[index].details[idx].product_id = product.data
        ? product.data.id
        : item.id;
      this.yinpianList[index].details[idx].product_name = product.data
        ? product.data.product_name
        : item.product_name;
      this.yinpianList[index].details[idx].production = product.data
        ? product.data.production
        : item.production;
      this.yinpianList[index].details[idx].unit = product.data
        ? product.data.number_unit
        : item.number_unit;
      if (product.data) {
        if (product.data.number) {
          this.yinpianList[index].details[idx].price = Number(
            product.data.price
          );
          this.yinpianList[index].details[idx].own = true;
        } else {
          this.yinpianList[index].details[idx].price = 0;
          this.yinpianList[index].details[idx].own = false;
        }
      } else {
        this.yinpianList[index].details[idx].price = 0;
        this.yinpianList[index].details[idx].own = false;
      }
      this.yinpianList[index].details[idx].number = product.data
        ? product.data.default_sell_number
        : 1;
      let price = this.yinpianList[index].details[idx].price;
      let num = this.yinpianList[index].details[idx].number;
      this.yinpianList[index].details[idx].amount = price * num;
    },
    async ypNumberChange(val, index, idx) {
      let pro_id = this.yinpianList[index].details[idx].product_id;
      let product = await productDetail({ product_id: pro_id });
      this.yinpianList[index].details[idx].stock = product.data
        ? product.data.number
        : 0;
      let price = this.yinpianList[index].details[idx].price;
      let num = this.yinpianList[index].details[idx].number;
      this.yinpianList[index].details[idx].amount = price * num;
    },
    surchargeHandleSelect(item, index) {
      this.surchargeList[index].surcharge_name = item.cost_dict_name;
      this.surchargeList[index].cost_price = item.sell_price;
      this.surchargeList[index].amount = item.sell_price;
    },
    async syProHandleSelect(item, index, shuyeidx, idx) {
      let product = await productDetail({ default_id: item.id });
      this.shuyeList[index].group[shuyeidx].details[idx].stock = product.data
        ? product.data.number
        : 0;
      this.shuyeList[index].group[shuyeidx].details[
        idx
      ].product_id = product.data ? product.data.id : item.id;
      this.shuyeList[index].group[shuyeidx].details[
        idx
      ].product_name = product.data
        ? product.data.product_name
        : item.product_name;
      this.shuyeList[index].group[shuyeidx].details[
        idx
      ].production = product.data ? product.data.production : item.production;
      this.shuyeList[index].group[shuyeidx].details[idx].pack = product.data
        ? product.data.pack
        : item.pack;
      this.shuyeList[index].group[shuyeidx].details[
        idx
      ].single_dose = product.data ? product.data.dose : item.dose;
      this.shuyeList[index].group[shuyeidx].details[
        idx
      ].single_unit = product.data ? product.data.dose_unit : item.dose_unit;
      this.shuyeList[index].group[shuyeidx].details[idx].number = product.data
        ? product.data.default_sell_number
        : 1;
      if (product.data) {
        if (product.data.number) {
          this.shuyeList[index].group[shuyeidx].details[idx].price = Number(
            product.data.price
          );
          this.shuyeList[index].group[shuyeidx].details[idx].own = true;
        } else {
          this.shuyeList[index].group[shuyeidx].details[idx].price = 0;
          this.shuyeList[index].group[shuyeidx].details[idx].own = false;
        }
      } else {
        this.shuyeList[index].group[shuyeidx].details[idx].price = 0;
        this.shuyeList[index].group[shuyeidx].details[idx].own = false;
      }
      let price = this.shuyeList[index].group[shuyeidx].details[idx].number;
      let num = this.shuyeList[index].group[shuyeidx].details[idx].price;
      this.shuyeList[index].group[shuyeidx].details[idx].amount = price * num;
      this.shuyeList[index].group[shuyeidx].details[idx].unit = product.data
        ? product.data.number_unit
        : item.number_unit;
    },
    async syNumberChange(val, index, shuyeidx, idx) {
      let pro_id = this.shuyeList[index].group[shuyeidx].details[idx]
        .product_id;
      let product = await productDetail({ product_id: pro_id });
      this.shuyeList[index].group[shuyeidx].details[idx].stock = product.data
        ? product.data.number
        : 0;
      let price = this.shuyeList[index].group[shuyeidx].details[idx].price;
      let num = this.shuyeList[index].group[shuyeidx].details[idx].number;
      this.shuyeList[index].group[shuyeidx].details[idx].amount = price * num;
    },
  },
};
</script>

<style lang="scss">
@import "@/assets/scss/outpatient/modules/prescription.scss";
</style>